﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ivory.Libs
{
    public sealed class FPSCounter
    {
        private TimeSpan _TimesinceLastUpdate;
        private int _FrameCount = 0;

        public int FPS { get; private set; }

        //ctor
        public FPSCounter()
        {
            FPS = 0;
            _TimesinceLastUpdate = TimeSpan.FromSeconds(0);
        }

        //Methods
        public void Update(GameTime time)
        {
            _TimesinceLastUpdate += time.ElapsedGameTime;
            _FrameCount++;

            if (_TimesinceLastUpdate >= TimeSpan.FromSeconds(1))
            {
                FPS = _FrameCount;
                _TimesinceLastUpdate = TimeSpan.FromSeconds(0);
                _FrameCount = 0;
            }
        }
    }
}
